import turtle
import math

# 画图加快
"""
为便于演示和美观，不进行严格1:1复现，仅作可爱卡通简化。
"""
# ------------- 基础设置 -------------
screen = turtle.Screen()
screen.setup(width=600, height=700)
screen.title('冰墩墩')
screen.bgcolor('white')

pen = turtle.Turtle()
pen.speed(3)
pen.hideturtle()

# ------------- 画圆函数 -------------
def draw_circle(x, y, r, color='black', fill=True, pensize=3):
    pen.up()
    pen.goto(x, y - r)
    pen.seth(0)
    pen.down()
    pen.pensize(pensize)
    pen.color(color)
    if fill:
        pen.begin_fill()
    pen.circle(r)
    if fill:
        pen.end_fill()
    pen.up()

# ------------- 画头部轮廓（带彩虹圈） -------------
def draw_rainbow_ring():
    colors = ['deepskyblue', 'violet', 'orangered', 'yellow', 'lime', 'deepskyblue']
    r = 180
    x, y = 0, 200
    for c in colors:
        draw_circle(x, y, r, c, fill=False, pensize=6)
        r -= 5

def draw_head():
    draw_circle(0, 200, 150, 'black', fill=False, pensize=5)
    draw_circle(0, 200, 142, 'white', fill=True, pensize=1)

# ------------- 头顶耳朵 -------------
def draw_ear():
    # 左耳
    draw_circle(-100, 370, 33, 'black')
    draw_circle(-100, 370, 21, 'white')
    # 右耳
    draw_circle(100, 370, 33, 'black')
    draw_circle(100, 370, 21, 'white')

# ------------- 画眼睛 -------------
def draw_eye():
    # 左眼
    draw_circle(-55, 230, 38, 'black')
    draw_circle(-55, 230, 20, 'white')
    draw_circle(-55, 230, 10, 'black')
    draw_circle(-60, 240, 4, 'white')
    # 右眼
    draw_circle(55, 230, 38, 'black')
    draw_circle(55, 230, 20, 'white')
    draw_circle(55, 230, 10, 'black')
    draw_circle(60, 240, 4, 'white')

# ------------- 画鼻子和嘴巴 -------------
def draw_nose_mouth():
    # 鼻子
    draw_circle(0, 210, 8, 'black')
    # 嘴
    pen.up()
    pen.goto(-18, 195)
    pen.setheading(-45)
    pen.width(3)
    pen.color('black')
    pen.down()
    pen.circle(20, 90)
    pen.up()

# ------------- 画身体和手脚 -------------
def draw_body():
    # 身体（大椭圆）
    pen.up()
    pen.goto(0, 66)
    pen.down()
    pen.seth(-80)
    pen.pensize(4)
    pen.fillcolor('white')
    pen.begin_fill()
    # 大椭圆
    for _ in range(2):
        pen.circle(150, 90)
        pen.circle(70, 90)
    pen.end_fill()
    pen.up()
    # 左手
    pen.goto(-100, 150)
    pen.pensize(36)
    pen.down()
    pen.seth(160)
    pen.color('black')
    pen.forward(80)
    pen.up()
    # 右手（高举）
    pen.goto(130, 180)
    pen.pensize(32)
    pen.down()
    pen.seth(60)
    pen.forward(110)
    pen.up()
    # 左脚
    pen.goto(-55, 50)
    pen.pensize(30)
    pen.down()
    pen.seth(-100)
    pen.forward(40)
    pen.up()
    # 右脚
    pen.goto(55, 55)
    pen.pensize(30)
    pen.down()
    pen.seth(-80)
    pen.forward(45)
    pen.up()

# ------------- 画五环 -------------
def draw_olympic_rings():
    ring_colors = ['blue', 'black', 'red', 'yellow', 'green']
    starts = [(-33, 0), (0, 0), (33, 0), (-18, -18), (18, -18)]
    pen.pensize(5)
    for (x, y), color in zip(starts, ring_colors):
        pen.up()
        pen.goto(x, y)
        pen.setheading(0)
        pen.color(color)
        pen.down()
        pen.circle(15)
    pen.up()

# ------------- 画logo -------------
def draw_logo():
    pen.up()
    pen.goto(0, 30)
    pen.color('black')
    pen.write('BEIJING 2022', align='center', font=('Arial', 13, 'bold'))
    draw_olympic_rings()
    pen.goto(0, 47)
    pen.color('deepskyblue')
    pen.write('"冰墩墩"', align='center', font=('Arial', 12, 'normal'))
    pen.up()

def main():
    draw_rainbow_ring()
    draw_head()
    draw_ear()
    draw_eye()
    draw_nose_mouth()
    draw_body()
    draw_logo()
    pen.goto(0, -260)
    pen.color('gray')
    pen.write('用turtle实现简易冰墩墩', align='center', font=('Arial', 11, 'normal'))
    turtle.done()

if __name__ == "__main__":
    main()